/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.model;

import com.aal.business.ProductManagementLocal;
import com.aal.entity.Product;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author quy
 */
public class ProductManagement {
    ProductManagementLocal productManagement = lookupProductManagementLocal();
    private int productid;
    private int categoryid;
    private String productname;
    private double unitprice;
    private String description;
    private double taxpercent;
    private String productimage;
    private int status;
    private double shippingpricecost;

    public int getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(int categoryid) {
        this.categoryid = categoryid;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public ProductManagementLocal getProductManagement() {
        return productManagement;
    }

    public void setProductManagement(ProductManagementLocal productManagement) {
        this.productManagement = productManagement;
    }

    public String getProductname() {
        return productname;
    }

    public void setProductname(String productname) {
        this.productname = productname;
    }
    

    public int getProductid() {
        return productid;
    }

    public void setProductid(int productid) {
        this.productid = productid;
    }

    public String getProductimage() {
        return productimage;
    }

    public void setProductimage(String productimage) {
        this.productimage = productimage;
    }

    public double getShippingpricecost() {
        return shippingpricecost;
    }

    public void setShippingpricecost(double shippingpricecost) {
        this.shippingpricecost = shippingpricecost;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public double getTaxpercent() {
        return taxpercent;
    }

    public void setTaxpercent(double taxpercent) {
        this.taxpercent = taxpercent;
    }

    public double getUnitprice() {
        return unitprice;
    }

    public void setUnitprice(double unitprice) {
        this.unitprice = unitprice;
    }

    public Product getProduct() {
        return getProductbyid(productid);
    }
    
    public List<Product> setSearchproductbyname(String productName)
    {
       return productManagement.searchproductbyName(productName);
    }
    public List<Product> setListallproducts(){
       return productManagement.listallproducts();
    }
    
    public List<Product> setSearchproductbycategory(int categoryId)
    {
        return (List<Product>) productManagement.searchproductbyCategory(categoryId);
    }
    public Product getProductbyid(int productId){
       return productManagement.searchproductbyID(productId);
    } 
    
    public boolean getAddproduct() 
    {
       return productManagement.addProduct(categoryid, productname, unitprice, description, taxpercent, productimage, status,shippingpricecost);
    }
    public boolean getEditproduct(){
       return productManagement.editProduct(productname, categoryid, unitprice, description, taxpercent, productimage, status, shippingpricecost);
    }
    public List<Product> getSearchproductbyname(){
       return productManagement.searchproductbyName(productname);
    }
    public List<Product> getListallproducts(){
       return productManagement.listallproducts();
    }
    public List<Product> getSearchproductbycategory(){
       return (List<Product>) productManagement.searchproductbyCategory(categoryid);
    }
    public List<Product> getListallproduct(){
        return productManagement.listallproducts();
    }
    private ProductManagementLocal lookupProductManagementLocal() {
        try {
            Context c = new InitialContext();
            return (ProductManagementLocal) c.lookup("java:global/AAL/AAL-ejb/ProductManagement!com.aal.business.ProductManagementLocal");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
